package com.wn16.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageHelper;
import com.wn16.bean.Account;
import com.wn16.service.AccountService;

@Controller
public class AccountController {

	@Autowired
	private AccountService accountService;
	@ResponseBody
	@RequestMapping(value = "findAccountById")
	public Object findAccount(@RequestParam("accountId") Integer accountId) {
		Account account = accountService.findAccountById(accountId);
		return account;
	}
	
	@ResponseBody
	@RequestMapping(value = "listAccounts")
	public List<Account> listAccounts(@RequestParam(defaultValue = "1", value = "pn") Integer pageNumber) {
		PageHelper.startPage(pageNumber, 5);
		List<Account> accountList = accountService.listAccounts();
		return accountList;
	}
	
	@ResponseBody
	@RequestMapping(value = "countAccounts")
	public int countAccounts() {
		accountService.countAccounts();
		int count = accountService.countAccounts();
		return count;
	}
	
	
}
